-- Copyright 2002-2008.  Adobe Systems, Incorporated.  All rights reserved.

-- This script illustrates how to create an alpha channel from text

-- The strategy is to create some text in a text layer and 
-- then copy that text to an alpha layer.

-- When you do that the text gets changed to a selection in 
-- the alph channel. We can then fill the selection with white
-- and thereby get an alpha channel corresponding to the text.


tell application "Adobe Photoshop CS4"
	activate
	
	-- The example uses copy/paste. This means that we need to make 
	-- Photoshop the active applicatiuon
	make new document
	
	-- Here we create the text that we want to generate an alpha channel for
	set myTextLayer to make new art layer in current document 
		with properties {kind:text layer}
	set properties of text object of myTextLayer to 
		{contents:"Hi there", size:18 as points}
	
	-- Now select the text and copy it to the a new alpha channel
	select all current document
	
	copy
	set myAlphaChannel to make new channel in current document 
		with properties {kind:masked area channel}
	set current channels of current document to {myAlphaChannel}
	paste
	
	-- Here we could manipulate the selection .
	-- If we for example wanted feather, we could do
	-- feather selection of current document by 3
	
	-- Fill the selection and clean up (removethe intermidiate text layer
	fill selection of current document with contents {class:RGB color, red:255, green:255, blue:255} 
		blend mode normal opacity 100
	
	deselect current document
	
	set current layer of current document to background layer of current document
	
	delete art layer 1 of current document
	
	set visible of every channel of current document to true
	
end tell
